package fab_api;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import net.sf.json.JSONArray;

public class FileReadOrWrite {

	public static void main(String[] args) {
		 File file = new File("d:/temp", "addfile.txt");  
	        try {  
	            file.createNewFile(); // 创建文件  
	        } catch (IOException e) {  
	            // TODO Auto-generated catch block  
	            e.printStackTrace();  
	        }  
	        // 向文件写入内容(输出流)  
	        String str = "[\"113.94509465557404,22.557814823171892,0\"]";  
//	        JSONArray ja = JSONArray.fromObject(str);
	        byte bt[] = new byte[1024];  
	        bt = str.getBytes();  
	        try {  
	            FileOutputStream in = new FileOutputStream(file);  
	            try {  
	               for(int n=0;n<10;n++){
	            	   System.out.println(n);
	            	   in.write(bt, 0, bt.length);  
		                in.close(); 
	               } 
	                // boolean success=true;  
	                // System.out.println("写入文件成功");  
	            } catch (IOException e) {  
	                // TODO Auto-generated catch block  
	                e.printStackTrace();  
	            }  
	        } catch (FileNotFoundException e) {  
	            // TODO Auto-generated catch block  
	            e.printStackTrace();  
	        }  
	        try {  
	            // 读取文件内容 (输入流)  
	            FileInputStream out = new FileInputStream(file);  
	            InputStreamReader isr = new InputStreamReader(out);  
	            int ch = 0;  
	        	   while ((ch = isr.read()) != -1) {  
		                System.out.print((char) ch);  
		            } 
	        } catch (Exception e) {  
	            // TODO: handle exception  
	        }  
	}
}
